/**
 * @author: li_jian
 * @version: 1.0
 * @date: 2020/7/7 01:46
 * @description： @link{https://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4?tpId=13&&tqId=11161&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking}
 */
public class JZ8_跳台阶 {

    public int JumpFloor(int target) {
        return withFor(target);
    }

    /**
     * 使用for循环
     *
     * @param target
     * @return
     */
    private int withFor(int target) {
        if (target <= 2)
            return target;

        int pre2 = 1, pre1 = 2;
        int ret = 0;
        for (int i = 3; i <= target; i++) {
            ret = pre1 + pre2;
            pre2 = pre1;
            pre1 = ret;
        }

        return ret;
    }

    /**
     * 使用递归
     *
     * @param target
     * @return
     */
    private int withRecursion(int target) {
        if (target <= 2)
            return target;

        return withRecursion(target - 1) + withRecursion(target - 2);
    }
}
